Fix issues with learner record api#3600
Merged
Merged
Conversation
OpenAPI ChangesShow/hide ## Changes for v0.yaml:Unexpected changes? Ensure your branch is up-to-date with |
846563c to
8f2d52a
Compare
cp-at-mit
approved these changes
May 26, 2026
ae2e738 to
031df19
Compare
for more information, see https://pre-commit.ci
Comment on lines
+636
to
+644
| def get_enrolled_program_or_404(user, program_id: int) -> Program: | ||
| """Return a program only if the user has an active enrollment for it.""" | ||
|
|
||
| enrollment = get_object_or_404( | ||
| ProgramEnrollment.objects.select_related("program"), | ||
| user=user, | ||
| program_id=program_id, | ||
| ) | ||
| return enrollment.program |
There was a problem hiding this comment.
Bug: The get_enrolled_program_or_404 function does not filter for active enrollments, allowing users who have unenrolled from a program to access their records.
Severity: MEDIUM
Suggested Fix
Update the get_object_or_404 call in get_enrolled_program_or_404 to filter out enrollments with a change_status of ENROLL_CHANGE_STATUS_UNENROLLED. This can be achieved by adding ~Q(change_status=ENROLL_CHANGE_STATUS_UNENROLLED) to the query, aligning it with existing enrollment checks.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: courses/views/v1/__init__.py#L636-L644
Potential issue: The new function `get_enrolled_program_or_404` is intended to return a
program only if a user has an active enrollment, as stated in its docstring. However,
the implementation retrieves any `ProgramEnrollment` object, including inactive ones for
users who have unenrolled (where `change_status` is `'unenrolled'`). This allows a user
who has unenrolled from a program to still access and share their learner record via
views like `GetLearnerRecordView` and `LearnerRecordShareView`. This behavior
contradicts the established pattern in the codebase, where other enrollment checks
explicitly filter out unenrolled records.
Did we get this right? 👍 / 👎 to inform future reviews.
Contributor
Author
There was a problem hiding this comment.
I think that's okay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What are the relevant tickets?
Fix https://github.com/mitodl/hq/issues/10918
Description (What does it do?)
Fix issues with learner record api
How can this be tested?
Create partner school
Go to http://mitxonline.odl.local:8013/api/records/program/2/ and verify the under "partner_schools" email field is not there.
Make sure you can't view your program record if you don't have an enrollment